package com.techpleiad.ieducation.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.techpleiad.ieducation.dao.ILoginDao;
import com.techpleiad.ieducation.entity.UserAccount;
import com.techpleiad.ieducation.exception.GenericDaoException;
import com.techpleiad.ieducation.exception.ServiceException;
import com.techpleiad.ieducation.service.ILoginService;

@Service("loginService")
@Transactional
public class LoginServiceImpl implements ILoginService {

	@Autowired
	private ILoginDao loginDao;
	
	public UserAccount login(final String username, final String password) throws ServiceException {
		UserAccount userAccount = null;
		try {
			userAccount = this.loginDao.get(username, password);
		} catch (GenericDaoException gde) {
			throw new ServiceException(gde);
		}
		return userAccount;
	}
	
	/**
	 * Sets the login dao.
	 *
	 * @param loginDao the new login dao
	 */
	public void setLoginDao(ILoginDao loginDao) {
		this.loginDao = loginDao;
	}
}
